#include "itemform.h"
#include "name.h"
#include "ui_itemform.h"
#include "create.h"
#include "stop.h"
#include "tomatoclock.h"
#include "ui_stop.h"
#include "databasemanager.h"

extern Stop *st;

itemform::itemform(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::itemform)
{
    ui->setupUi(this);
    ui->pushButton->setStyleSheet(
        "QPushButton {"
        "background-color: rgba(0, 191, 255, 50);"
        "color: white;"
        "border: none;"
        "}"
        );
}

itemform::~itemform()
{
    delete ui;
}

void itemform::setItemInfo(QString name,QString type,int duration,QString date)
{
    ui->label->setText(name);
    ui->label_2->setText(type);
    ui->label_3->setText(QString::number(duration));
    ui->label_4->setText(date);
}

void itemform::on_pushButton_clicked()
{
    this->close();
    QString s1=ui->label->text();
    QString s3=ui->label_2->text();
    int length=ui->label_3->text().toInt();

    DatabaseManager::insert_history(s1,s3,length);

    Stop *s=new Stop;
    s->show();

    int hour=length/60;
    int minute=length-hour*60;
    int second=0;
    if(minute==0){
        minute=1;
    }
    st->ui->project_1->setText(s1);
    st->m_time=hour*360000+minute*6000+second*100;
    st->cm_time=hour*360000+minute*6000+second*100;
    st->ui->label->setTime(st->cm_time-100);
    emit itemDataChanged();
    this->close();
}

